package cx.ath.skyflyer.gpslog.nmea;

import j2meunit.framework.*;

/**
 *
 * @author Ahti Legonkov
 */
public class TimeTest extends TestCase {

    public TimeTest() {
    }

    private TimeTest(String name, TestMethod method) {
        super(name, method);
    }

    public void setUp() throws Exception {
        super.setUp();
    }

    public void tearDown() throws Exception {
        super.tearDown();
    }

    private void testGetHour() {
        try {
            Time t = new Time("123456.789");
            assertEquals(12, t.getHour());
            assertEquals(34, t.getMinute());
            assertEquals(56, t.getSecond());
            assertEquals(789, t.getMillisecond());

            String s = t.toString();
            assertEquals("12:34:56.789", t.toString());
        }
        catch (Exception ex) {
            fail("Unexpected exception");
        }
    }

    private void testGetMinute() {
    }

    private void testGetMillisecond() {
    }

    private void testToString() {
    }

    private void testNumberFormatException() {
        try {
            Time t = new Time("abcdefg");
            fail("NumberFormatException expected");
        }
        catch (NumberFormatException ex) {
        }
        catch (Throwable e) {
            fail("Wrong exception");
        }
    }

    private void testSub() {
        try {
            Time a = new Time("223344");
            Time b = new Time("010203");

            double expected = 3600*(22-1) + 60*(33-2) + (44-3);

            assertEquals(expected, a.sub(b));
        }
        catch (Throwable e) {
            fail("Unexpected exception");
        }
    }

    public Test suite() {
		TestSuite ts = new TestSuite();

        ts.addTest(new TimeTest("testGetHour", new TestMethod() {
            public void run(TestCase tc) {
                ((TimeTest)tc).testGetHour();
            }
        }));

        ts.addTest(new TimeTest("testGetMinute", new TestMethod() {
            public void run(TestCase tc) {
                ((TimeTest)tc).testGetMinute();
            }
        }));

        ts.addTest(new TimeTest("testGetMillisecond", new TestMethod() {
            public void run(TestCase tc) {
                ((TimeTest)tc).testGetMillisecond();
            }
        }));

        ts.addTest(new TimeTest("testToString", new TestMethod() {
            public void run(TestCase tc) {
                ((TimeTest)tc).testToString();
            }
        }));

        ts.addTest(new TimeTest("testSub", new TestMethod() {
            public void run(TestCase tc) {
                ((TimeTest)tc).testSub();
            }
        }));

        ts.addTest(new TimeTest("testNumberFormatException", new TestMethod() {
            public void run(TestCase tc) {
                ((TimeTest)tc).testNumberFormatException();
            }
        }));

        return ts;
    }
}

